package gui.Main;

import gui.mapper.NodeListing;

import java.io.Serializable;
import java.net.InetAddress;
import java.net.UnknownHostException;

import network.GUICoreProxy;
import network.GlobalObjectId;
import network.LocalObjectId;
import network.ObjectDB;
import network.PortNumber;

public class GUICore implements Serializable {
	private static final long serialVersionUID = 7485484473629782723L;

	private LocalObjectId localObjectId;

	public GUICore() {
		localObjectId = new LocalObjectId();
	}

	public int refresh(int targetSize) {
		NodeListing nodes = GUI.getSingleton().getHyPeerWebDebugger().getMapper().getNodeListing();
		nodes.refresh(targetSize);
		return 1;
	}

	public LocalObjectId getLocalObjectId() {
		return localObjectId;
	}
	
	public Object writeReplace() {
		try {
			ObjectDB.getSingleton().store(getLocalObjectId(), this);
			return new GUICoreProxy(new GlobalObjectId(InetAddress.getLocalHost().getHostAddress(), PortNumber.getApplicationsPortNumber(), getLocalObjectId()));
		} catch (UnknownHostException e) {
			e.printStackTrace();
			return null;
		}
	}
}
